package com.hejia.alauda.mongodb;

import java.io.Serializable;
import java.lang.reflect.Method;

import org.bson.types.ObjectId;

public class BaseMongoEntity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7767088606313316134L;
	
	private ObjectId id; //ID
	
	private String createDate; //创建时间 用String主要是为了在mongodb里好查询
	
	private String modifyDate; //修改时间 用String主要是为了在mongodb里好查询

	public ObjectId getId() {
		return id;
	}

	public void setId(ObjectId id) {
		this.id = id;
	}

	public String getCreateDate() {
		return createDate;
	}

	public void setCreateDate(String createDate) {
		this.createDate = createDate;
	}

	public String getModifyDate() {
		return modifyDate;
	}

	public void setModifyDate(String modifyDate) {
		this.modifyDate = modifyDate;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder("[");
		Method[] methods = this.getClass().getMethods();
		try {
			for(int k = 0;k < methods.length;k++){
				if(methods[k].getName().startsWith("get") && !methods[k].getName().endsWith("Class")){
					sb.append(methods[k].getName().substring(3));
					sb.append('=');
					sb.append(methods[k].invoke(this, null));
					sb.append(',');
				} else if(methods[k].getName().startsWith("is")){
					sb.append(methods[k].getName().substring(2));
					sb.append('=');
					sb.append(methods[k].invoke(this, null));
					sb.append(',');
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		//去掉最后一个逗号
		sb.deleteCharAt(sb.length() - 1);
		sb.append(']');
		return sb.toString();
	}
}
